package com.database.dao.impl;

import javax.inject.Named;

import org.hibernate.Session;
import org.springframework.stereotype.Component;

import com.database.bean.User;
import com.database.dao.UserDao;

@Named("userDao")
@Component
public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public UserDaoImpl() {
		super(User.class);
	}
	
	@Override
	public User getUserByNickname(String nickname) {
		Session session = getSession();
		User user=(User) session.createQuery("from User where nickname = :nickname").setParameter("nickname", nickname).uniqueResult();
		closeSession();
		return user;
		
	}

	@Override
	public User reloadCompanyRoundDecisionAndResults(User user) {
		Session session = getSession();
		session.refresh(user);
		user.getCompanyRoundDecisionAndResults();
		closeSession();
		return user;
	}
	
	@Override
	public User reloadGame(User user) {
		Session session = getSession();
		session.refresh(user);
		user.getGame();
		closeSession();
		return user;
	}


}
